package com.tesis_2.Utils;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.RatingBar;
import android.widget.TextView;

import com.example.tesis_2.R;
import com.tesis_2.MO.MOComentario;
import com.tesis_2.MO.MODscore;

public class UTDscoresAdapter extends  ArrayAdapter<MODscore> {
	
	private final Context context;
	private final ArrayList<MODscore> values;
	
	public UTDscoresAdapter(Context context,ArrayList<MODscore> objects) {
		super(context, R.layout.activity_uidscore, objects);
		this.context = context;
		this.values = objects;
		
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context
			.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 
		View rowView = inflater.inflate(R.layout.activity_uidscore, parent, false);
		
		((TextView) rowView.findViewById(R.id.txvPlato_uidscore)).setText(((MODscore) getItem(position)).getDishname());
		((RatingBar) rowView.findViewById(R.id.rbRate_uidscore)).setRating((((MODscore) getItem(position)).getRate()));
		((RatingBar) rowView.findViewById(R.id.rbRate_uidscore)).setTag(position);
		((RatingBar) rowView.findViewById(R.id.rbRate_uidscore)).setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
			public void onRatingChanged(RatingBar ratingBar, float rating, boolean user) {
				//if(!fromUser) return;
				
				int index = (Integer)(ratingBar.getTag());
				values.get(index).setRate(((int) rating));
			}
		});
		
		return rowView;
	}
	
	
}
